Installation of Prophet

pystan>=3.0 is currently not supported

pip uninstall pystan --yes && pip install pystan==2.19.1.1 && pip install prophet

Python API

Basic Setup

Import libraries

Import data

Missing Value

Rename Columns

Prophet also imposes the strict condition that the input columns must be named as:

So, we must rename the columns in our dataframe.

Visualize the data

The figure shows that the data have seasonality and trend

Train Test Split

Time Series Forecasting with Prophet

Prophet returns a large DataFrame with many interesting columns, but we subset our output to the columns most relevant to forecasting. These are:

Plotting the Forecasted Components

Adding ChangePoints to Prophet

We can view the dates where the chagepoints occurred.

The number of changepoints can be set by using the n_changepoints parameter when initializing prophet.

Adjusting Trend

Forecast Quality Evaluation

We are also going to define a helper function that we will use to gauge the quality of our forecasting with MAPE, MSE, RMSE, and MAE error measures:

Model Visualization